{include file=header.html}
<!--<script type="text/javascript" charset="utf-8" src="{$wap_site}/templates/style/mlselection.js" ></script>-->
<script type="text/javascript" src="{lib file=jquery.plugins/jquery.validate.js}" charset="utf-8"></script>
<div class="conter">
  {include file="header.common.html"}
  <div class="layerbox_kuan"> 
  <form method="post" action="index.php?app=my_address&act={$act}&addr_id={$address.addr_id}{if $smarty.get.for_cart}&for_cart={$smarty.get.for_cart}{/if}{if $smarty.get.sh_null}&sh_null={$smarty.get.sh_null}{/if}" id="address_form">
  <div class="layerbox">
  <table width="100%" class="table_fill">
    <tr>
      <th><em>*</em>选择类型：</th>
      <td><select name="ddl_type" id="ddl_type" class="select_class">
            <option value="1" {if $address.ddl_type neq '2'}selected="selected"{/if}>收货人地址</option>
            <option value="2" {if $address.ddl_type eq '2'}selected="selected"{/if}>发货人地址</option>
          </select></td>
    </tr>
    <tr>
      <th><em>*</em>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</th>
      <td><input type="input" class="text width_normal" name="consignee" id="consignee" value="{$address.consignee|escape}"/><label class="field_message"></label></td>
    </tr>
    <tr>
      <th><em>*</em>手机电话：</th>
      <td><input type="input" class="text width_normal" name="phone_mob" id="phone_mob" value="{$address.phone_mob|escape}"/><label class="field_message"></label></td>
    </tr>
    <!--{if $smarty.get.act eq 'has_hide'}-->
    <tr>
      <th><em>*</em>所在地区：</th>
      <td id="region">
       <!-- {if $address.region_id} --><div style="line-height:26px;">{$address.region_name|escape}</div><!-- {else} --><!-- {/if} -->
       <select style="margin-bottom:8px" class="select_class" onchange="hide_error();"><option>请选择省份...</option>{html_options options=$regions}</select>
       <input type="hidden" name="region_id" value="{$address.region_id}" id="region_id" />
       <input type="hidden" name="region_name" value="{$address.region_name|escape}" id="region_name"/></td>
    </tr>  
    <!-- {/if} -->  
    <tr>
      <th><em>*</em>国&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;家：</th>
      <td><input type="input" class="text width_normal" name="txt_country" id="txt_country" value="{$address.txt_country|escape}"/><label class="field_message"></label></td>
    </tr>
    <tr>
      <th><em>*</em>选择地区：</th>
      <td><input name="txt_province" type="text" id="txt_province" class="text" style="width:70px;" value="{$address.txt_province}"/> 省/州&nbsp;
          <input name="txt_city" type="text" id="txt_city" class="text" style="width:70px;" value="{$address.txt_city}"/> 市&nbsp;
          <div id="divQu" style="display:{if $address.ddl_type eq '2'}none{else}inline{/if}"><input name="txtqu" type="text" id="txtqu" class="text" style="width:70px;"  value="{$address.txtqu}"//> 区/县</div>
      </td>
    </tr>
    <tr>
      <th><em>*</em>详细地址：</th>
      <td><input type="input" class="text width_normal" name="address" id="address" value="{$address.address|escape}"/><label class="field_message"></label></td>
    </tr>            
    <tr>
      <th>邮政编码：</th>
      <td><input type="input" class="text width_normal" name="zipcode" id="zipcode" value="{$address.zipcode|escape}"/><label class="field_message"></label></td>
    </tr>
    <tr>
      <th>邮箱地址：</th>
      <td><input type="input" class="text width_normal" name="txt_email" id="txt_email" value="{$address.txt_email|escape}" placeholder="Email地址" /><label class="field_message"></label></td>
    </tr>
    <tr>
      <th>身份证类别：</th>
      <td><label><input id="idpic" type="radio" name="idpic" value="rbtnyes" {if $address.idpic neq 'rbtnno'}checked="checked"{/if}/> 大陆地区</label>&nbsp;&nbsp;
          <label><input id="idpic" type="radio" name="idpic" value="rbtnno" {if $address.idpic eq 'rbtnno'}checked="checked"{/if}/> 非大陆地区</label></td>
    </tr> 
    <tr>
      <th><em>*</em>身份证号码：</th>
      <td><input type="input" class="text width_normal" name="txtidcode" id="txtidcode" value="{$address.txtidcode|escape}" placeholder="身份证号码必填方便清关"/><label class="field_message"></label></td>
    </tr>             
  </table>
  </div> 
  <div id="warning"></div>
  <p><input type="Submit" class="button_css" value="确认保存"></p> 
  </form>
  </div>  
{include file=footer.html}
</div>
<script type="text/javascript">
//<!CDATA[
$(function(){
	//regionInit("region");
	$(".button_css").click(function(){
	  return checkTelEnglish();
	  $('#address_form').validate({
		  errorPlacement: function(error, element){
			  var _message_box = $(element).parent().find('.field_message');
			  _message_box.find('.field_notice').hide();
			  _message_box.append(error);
		  },
		  onkeyup : false,
		  rules : {
			  consignee : {required : true },
			  //phone_mob : {required : true, checkTelEnglish:true},
			  txt_country : {required : true },
			  txt_province : {required : true },
			  txt_city : {required : true },
			  txtqu : {required : check_txtqu },
			  address   : {required : true },
			  zipcode : {required : true, digits : true },
			  txt_email : { email : true },
			  txtidcode : {required : true, checkIdcard:true }
		  },
		  messages : {
			  consignee : {required : '请填写姓名. ' },
			  //phone_mob : {required : '请填写正确的手机电话号码. ', checkTelEnglish: '格式有误，请输入10-13位的号码，且只能输入数字或者-横线. '},
			  txt_country : {required : '请填写国家. ' },
			  txt_province : {required : '请填写省或州. ' },
			  txt_city : {required : '请填写城市. ' },
			  txtqu : {required : '请填写区或县. ' },
			  address   : {required : '{$lang.address_required}. ' },
			  zipcode : {required : '请填写邮政编码. ' , digits : '邮政编码必须为数字'},
			  txt_email : { email : '邮箱地址格式有误，请正确输入' },
			  txtidcode : {required : '请填写有效的身份证号码. ', checkIdcard:'错误格式的身份证号码，请输入有效的身份证号码' }
		  }
	  });
	});	
	$('#ddl_type').change(function(){ 
		var select_val = $(this).children('option:selected').val(); 
		if(select_val == '2'){
			$("#divQu").css("display", "none");
			$("input[type=radio][name=idpic][value='rbtnno']").attr("checked",true);  
		}else{
			$("#divQu").css("display", "inline");
			$("input[type=radio][name=idpic][value='rbtnyes']").attr("checked",true); 
		}
	}) 	
});
function checkTelEnglish()
{ 
  if ($("#phone_mob").val() == "") { 
		  alert("请填写正确的手机电话号码");$("#phone_mob").focus(); return false; 
  }
  if($("#ddl_type").val() == '2'){//发货人
	  var newstr = $("#phone_mob").val().replace(/\-/g, "");
	  if(/^[0-9\\-]*$/.test($("#phone_mob").val()) == false){ alert("当前是发货人地址，手机/电话只能输入数字或者-横线，请正确输入");$("#phone_mob").focus(); return false; }
	  if(newstr.length < 10 || newstr.length > 13){ alert("当前是发货人地址，您输入的手机/电话的格式有误，请输入10-13位的手机/电话号码");$("#phone_mob").focus(); return false; }	  
  }else{ //收货人
      if(checkTel($("#phone_mob").val()) == false){ alert("当前是收货人地址，请输入中国地区正确的手机号码或者电话号码");$("#phone_mob").focus(); return false; }
  }

  return true;
}
function checkTel(value){
	var isPhone = /^([0-9]{3,4}-)?[0-9]{7,8}$/;
	var isMob=/^((\+?86)|(\(\+86\)))?(13[0123456789][0-9]{8}|15[012356789][0-9]{8}|18[02356789][0-9]{8}|147[0-9]{8})$/;
	if(isMob.test(value)||isPhone.test(value)){
		return true;
	}else{
		return false;
	}
}
function check_txtqu(){
	if ($('#divQu').css('display')=="inline"){
		return true;
	}else{
		return false;
	}
}
function hide_error(){
    $('#region').find('.error').hide();
}
//]]>
</script>
</body>
</html>